home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / PrinterGX.cpp < prev    next >
Encoding:
Text File  |  1996-04-22  |  17.9 KB  |  673 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PrinterGX.cpp
  3.  
  4.     Contains:    QuickDraw GX printing support for OpenDoc printing utility
  5.  
  6.     Owned by:    Jens Alfke  (Written by Thomas Weisbach & Jens Alfke)
  7.  
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      2/2/96    JA        Filled in header comments.
  13.          <1>      2/2/96    JA        first checked in
  14.  
  15.     To Do:
  16. */
  17.  
  18.  
  19. // -- OpenDoc --
  20.  
  21. #ifndef _ALTPOINT_
  22. #include <AltPoint.h>
  23. #endif
  24.  
  25. #ifndef SOM_ODCanvas_xh
  26. #include <Canvas.xh>
  27. #endif
  28.  
  29. #ifndef SOM_ODClipboard_xh
  30. #include <Clipbd.xh>
  31. #endif
  32.  
  33. #ifndef SOM_Module_OpenDoc_Commands_defined
  34. #include <CmdDefs.xh>
  35. #endif
  36.  
  37. #ifndef SOM_ODDispatcher_xh
  38. #include <Disptch.xh>
  39. #endif
  40.  
  41. #ifndef SOM_ODFacet_xh
  42. #include <Facet.xh>
  43. #endif
  44.  
  45. #ifndef SOM_ODFrame_xh
  46. #include <Frame.xh>
  47. #endif
  48.  
  49. #ifndef SOM_ODMenuBar_xh
  50. #include <MenuBar.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODSession_xh
  54. #include <ODSessn.xh>
  55. #endif
  56.  
  57. #ifndef SOM_ODStorageSystem_xh
  58. #include <ODStor.xh>
  59. #endif
  60.  
  61. #ifndef SOM_ODPart_xh
  62. #include <Part.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODPlatformTypeList_xh
  66. #include <PfTypLs.xh>
  67. #endif
  68.  
  69. #ifndef SOM_ODShape_xh
  70. #include <Shape.xh>
  71. #endif
  72.  
  73. #ifndef SOM_Module_OpenDoc_StdProps_defined
  74. #include <StdProps.xh>
  75. #endif
  76.  
  77. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  78. #include <StdTypes.xh>
  79. #endif
  80.  
  81. #ifndef SOM_ODTransform_xh
  82. #include <Trnsform.xh>
  83. #endif
  84.  
  85. #ifndef SOM_ODWindowState_xh
  86. #include <WinStat.xh>
  87. #endif
  88.  
  89. // -- OpenDoc Utilities --
  90.  
  91. #ifndef _EXCEPT_
  92. #include <Except.h>
  93. #endif
  94.  
  95. #ifndef _ISOSTR_
  96. #include <ISOStr.h>
  97. #endif
  98.  
  99. #ifndef _DLOGUTIL_
  100. #include <DlogUtil.h>
  101. #endif
  102.  
  103. #ifndef _ODDEBUG_
  104. #include <ODDebug.h>
  105. #endif
  106.  
  107. #ifndef _ODNEW_
  108. #include <ODNew.h>
  109. #endif
  110.  
  111. #ifndef _ODUTILS_
  112. #include <ODUtils.h>
  113. #endif
  114.  
  115. #ifndef _STORUTIL_
  116. #include <StorUtil.h>
  117. #endif
  118.  
  119. #ifndef _TEMPOBJ_
  120. #include <TempObj.h>
  121. #endif
  122.  
  123. #ifndef _USERSRCM_
  124. #include <UseRsrcM.h>
  125. #endif
  126.  
  127. // -- MacToolbox --
  128.  
  129. #ifndef __GXGRAPHICS__
  130. #include <GXGraphics.h>
  131. #endif
  132.  
  133. #ifndef __TEXTUTILS__
  134. #include <TextUtils.h>
  135. #endif
  136.  
  137. // -- Printer --
  138. #define _PRINTER_PRIVATE_
  139. #ifndef _PRINTER_
  140. #include "Printer.h"
  141. #endif
  142.  
  143. #pragma segment Printer
  144.  
  145.  
  146. //---------------------------------------------------------------------------------
  147. // THROW_IF_JOB_ERROR  [static]
  148. //---------------------------------------------------------------------------------
  149.  
  150. static void
  151. THROW_IF_JOB_ERROR( gxJob job )
  152. {
  153.     OSErr err= GXGetJobError(job);
  154.     if( err ) THROW(err);
  155. }
  156.  
  157.  
  158. //=================================================================================
  159. // PrintingEventHandler declaration
  160. //    A stack-based object that temporarily installs a GX printing event override
  161. //    to forward some events (activate/deactivate/etc.) to the OpenDoc dispatcher.
  162. //=================================================================================
  163.  
  164. class PrintingEventHandler :Destructo
  165. {
  166. public:
  167.     PrintingEventHandler(Environment* ev, ODSession* session, gxJob job);
  168.     ~PrintingEventHandler();
  169.     
  170.     static OSErr PrintingEventOverride(EventRecord *anEvent, Boolean filterEvent);
  171.  
  172. private:
  173.     static Environment*     sEv;
  174.     static ODSession*        sSession;
  175.     static gxJob            sgxJob;
  176.  
  177.     gxJob                    fgxJob;
  178.     GXPrintingEventUPP        fPrintingEventOverrideProcPtr;
  179. };
  180.  
  181.  
  182. //=================================================================================
  183. // CGXPrinter implementation
  184. //=================================================================================
  185.  
  186. //---------------------------------------------------------------------------------
  187. // CGXPrinter::CGXPrinter
  188. //---------------------------------------------------------------------------------
  189.  
  190. CGXPrinter::CGXPrinter( )
  191. {
  192.     fJob = kODNULL;
  193.     fViewPort = kODNULL;
  194.     fQDPort = kODNULL;
  195.     fPrintAShapeProcPtr = kODNULL;
  196.     fJobStarted = kODFalse;
  197.     fPageOpen = kODFalse;
  198. }
  199.  
  200. //---------------------------------------------------------------------------------
  201. // CGXPrinter::~CGXPrinter
  202. //---------------------------------------------------------------------------------
  203.  
  204. CGXPrinter::~CGXPrinter()
  205. {
  206.     if( fJob ) {
  207.         GXDisposeJob(fJob);
  208.     }
  209.     if( fPrintingOpen ) {
  210.         GXExitPrinting();
  211.         fPrintingOpen = kODFalse;
  212.     }
  213. }
  214.     
  215. //---------------------------------------------------------------------------------
  216. // CGXPrinter::Initialize
  217. //---------------------------------------------------------------------------------
  218.  
  219. void CGXPrinter::Initialize( Environment *ev, ODStorageUnit *su )
  220. {
  221.     // We can't open and close GX printing on every operation the way we could
  222.     // with QD. We have to leave it open for as long as we are going to use it,
  223.     // or else objects like fJob will be invalidated. So we open it now and
  224.     // don't close it until we get to the destructor.
  225.     
  226.     inherited::Initialize(ev,su);
  227.     THROW_IF_ERROR( GXInitPrinting() );
  228.     fPrintingOpen = kODTrue;
  229. }
  230.  
  231. //---------------------------------------------------------------------------------
  232. // CGXPrinter::ReadJobFromHandle
  233. //---------------------------------------------------------------------------------
  234.  
  235. ODPlatformPrintJob CGXPrinter::ReadJobFromHandle(ODValueType valueType, ODHandle h)
  236. {
  237.     // We can either read a streamed-out GX job or convert an old-style THPrint.
  238.     
  239.     if( ODISOStrEqual(valueType,kODTypeGXPageSetup) ) {
  240.         fJob = GXUnflattenJobFromHdl(kODNULL, (Handle)h);
  241.         
  242.     } else if( ODISOStrEqual(valueType,kODTypeQuickDrawPageSetup) ) {
  243.         if( GXNewJob(&fJob) == noErr )
  244.             GXConvertPrintRecord(fJob, (THPrint)h);
  245.         
  246.     } else
  247.         WARN("Unknown value type");
  248.         
  249.     ODDisposeHandle(h);
  250.     if( fJob && GXGetJobError(fJob) ) {
  251.         WARN("Error %d reading GX job",GXGetJobError(fJob));
  252.         if( fJob ) GXDisposeJob(fJob);
  253.         fJob = kODNULL;
  254.     }
  255.     
  256.     return (ODPlatformPrintJob)fJob;
  257. }
  258.  
  259. //---------------------------------------------------------------------------------
  260. // CGXPrinter::CreateNewJob
  261. //---------------------------------------------------------------------------------
  262.  
  263. ODPlatformPrintJob CGXPrinter::CreateNewJob()
  264. {
  265.     // Throw an exception if we can't create a print job, since we will certainly
  266.     // not be able to continue!
  267.     
  268.     THROW_IF_ERROR( GXNewJob(&fJob) );
  269.     return (ODPlatformPrintJob) fJob;
  270. }
  271.  
  272. //---------------------------------------------------------------------------------
  273. // CGXPrinter::CopyJobToHandle
  274. //---------------------------------------------------------------------------------
  275.  
  276. ODHandle CGXPrinter::CopyJobToHandle( )
  277. {
  278.     ODHandle jobHandle = ODNewHandle(0);
  279.     GXFlattenJobToHdl(fJob, (Handle)jobHandle);
  280.     if( GXGetJobError(fJob) ) {
  281.         ODDisposeHandle(jobHandle);
  282.         THROW_IF_ERROR(GXGetJobError(fJob));
  283.     }
  284.     return jobHandle;
  285. }
  286.  
  287. //---------------------------------------------------------------------------------
  288. // CGXPrinter::GetPageRect
  289. //---------------------------------------------------------------------------------
  290.  
  291. ODRect CGXPrinter::GetPageRect( Environment *ev )
  292. {
  293.     // Doesn't handle custom page formats; assumes all pages have same bbox.
  294.     
  295.     ODRect pageRect;
  296.     
  297.     this->GetPlatformPrintJob(ev);        // Force internalization of fJob
  298.     
  299.     gxFormat pageFormat = GXGetJobFormat(fJob, 1);
  300.     GXGetFormatDimensions(pageFormat, (gxRectangle*) &pageRect, kODNULL);
  301.     
  302.     return pageRect;
  303. }
  304.  
  305. //---------------------------------------------------------------------------------
  306. // CGXPrinter::CreatePrintingPlatformCanvas
  307. //---------------------------------------------------------------------------------
  308.  
  309. ODPlatformCanvas
  310. CGXPrinter::CreatePrintingPlatformCanvas( Environment* ev, ODGraphicsSystem g,
  311.                                             ODFrame *initiator, ODShape *area )
  312. {
  313.     switch( g ) {
  314.         case kODQuickDrawGX: {
  315.             // Start print job & create printing viewport.
  316.             long firstPage, lastPage;
  317.             GXGetJobPageRange(fJob, &firstPage, &lastPage);
  318.             ODUShort pageCount = this->CountPages(ev, area);
  319.             if ( lastPage > pageCount )
  320.                 lastPage = pageCount;
  321.         
  322.             Str255 windowTitle;
  323.             {
  324.                 TempODWindow w = fSession->GetWindowState(ev)->AcquireFrontRootWindow(ev);
  325.                 GetWTitle( w->GetPlatformWindow(ev), windowTitle );
  326.             }
  327.             
  328.             GXStartJob(fJob, windowTitle, lastPage - firstPage + 1);
  329.             THROW_IF_ERROR(GXGetJobError(fJob));
  330.             fJobStarted = kODTrue;
  331.             
  332.             WASSERT(fViewPort==kODNULL);
  333.             fViewPort = GXNewViewPort(gxScreenViewDevices);
  334.             return (ODPlatformCanvas) fViewPort;
  335.             // The viewport isn't hooked up to the job yet,
  336.             // but it will be in OpenPage.
  337.         }
  338.         
  339.         case kODQuickDraw: {
  340.             // Find the frame's window's port:
  341.             TempODWindow window = initiator->AcquireWindow(ev);
  342.             fQDPort = window->GetPlatformWindow(ev);
  343.  
  344.             fPrintAShapeProcPtr = NewgxShapeSpoolProc(CGXPrinter::PrintAShape);
  345.         
  346.             return (ODPlatformCanvas) fQDPort;
  347.         }
  348.         
  349.         default: {
  350.             THROW(kODErrInvalidGraphicsSystem);
  351.             return kODNULL;
  352.         }
  353.     }
  354. }
  355.  
  356. //---------------------------------------------------------------------------------
  357. // CGXPrinter::OpenPage
  358. //---------------------------------------------------------------------------------
  359.  
  360. void CGXPrinter::OpenPage( Environment*, ODUShort page )
  361. {
  362.     // Get the specific page format. (note: we don't support
  363.     // custom page setup, yet, so we always get the first page's
  364.     // format).
  365.     
  366.     gxFormat pageFormat = GXGetJobFormat(fJob, 1);
  367.     
  368.     GXStartPage(fJob, page, pageFormat, 1, &fViewPort);                                
  369.     
  370.     THROW_IF_JOB_ERROR(fJob);
  371.     
  372.     fPageOpen = kODTrue;
  373.  
  374.     // Now install the QD->GX translator:
  375.     Point     patStretch = {1, 1};
  376.     Rect    everywhereRect = {0,0,32767,32767};
  377.  
  378.     GXInstallQDTranslator(fQDPort,
  379.                           gxDefaultOptionsTranslation,
  380.                           &everywhereRect, &everywhereRect,
  381.                           patStretch, 
  382.                           fPrintAShapeProcPtr,
  383.                           this);
  384. }
  385.  
  386. //---------------------------------------------------------------------------------
  387. // CGXPrinter::ClosePage
  388. //---------------------------------------------------------------------------------
  389.  
  390. void 
  391. CGXPrinter::ClosePage( Environment* )
  392. {
  393.     if( fPageOpen ) {    
  394.         // Finish the page.
  395.         if( fQDPort )
  396.             GXRemoveQDTranslator(fQDPort, kODNULL);
  397.  
  398.         GXFinishPage(fJob);
  399.         
  400.         fPageOpen = kODFalse;
  401.         
  402.         THROW_IF_JOB_ERROR(fJob);
  403.     }
  404. }
  405.  
  406. //---------------------------------------------------------------------------------
  407. // CGXPrinter::CleanupPrintingEnv
  408. //---------------------------------------------------------------------------------
  409.  
  410. void CGXPrinter::CleanupPrintingEnv(Environment* ev, ODFrame* initiator)
  411. {
  412.     // This routine should not throw exeptions and must call the inherited method.
  413.     
  414.     if( fJobStarted ) {
  415.         fJobStarted = kODFalse;
  416.         GXFinishJob(fJob);
  417.         if( GXGetJobError(fJob) )
  418.             WARN("Error %d finishing job",GXGetJobError(fJob));
  419.     }
  420.     
  421.     if( fPrintAShapeProcPtr ) {
  422.         DisposeRoutineDescriptor(fPrintAShapeProcPtr);
  423.         fPrintAShapeProcPtr = kODNULL;
  424.     }
  425.  
  426.     if( fViewPort ) {
  427.         GXDisposeViewPort(fViewPort);
  428.         fViewPort = kODNULL;
  429.     }
  430.     
  431.     inherited::CleanupPrintingEnv(ev,initiator);
  432. }
  433.  
  434. //---------------------------------------------------------------------------------
  435. // CGXPrinter::EnableMenus
  436. //---------------------------------------------------------------------------------
  437.  
  438. void CGXPrinter::EnableMenus( Environment* ev, ODBoolean enable )
  439. {
  440.     // While printing/page-setup dialogs are up, we need to disable all irrelevant
  441.     // menu commands except the standard Undo/Cut/Copy/Paste/Clear. We also need
  442.     // to fill out an EditMenuRec for GX to tell it where those commands are.
  443.     
  444.     ODWindowState* windowState = fSession->GetWindowState(ev);
  445.     TempODMenuBar mbar = windowState->AcquireCurrentMenuBar(ev);
  446.  
  447.     if (enable)
  448.     {
  449.         // Called after dialog goes away.
  450.         mbar->EnableAll(ev);
  451.         mbar->EnableCommand(ev, kODCommandAbout, kODTrue);
  452.     }
  453.     else
  454.     {
  455.         // Called before dialog comes up.
  456.         mbar->DisableAll(ev);
  457.         mbar->EnableCommand(ev, kODCommandAbout, kODFalse);
  458.         
  459.         ODMenuID menuID;
  460.         
  461.         mbar->GetMenuAndItem(ev, kODCommandUndo, &(fEditMenuRec.editMenuID), &(fEditMenuRec.undoItem));
  462.         mbar->GetMenuAndItem(ev, kODCommandCut, &menuID, &(fEditMenuRec.cutItem));
  463.         mbar->GetMenuAndItem(ev, kODCommandCopy, &menuID, &(fEditMenuRec.copyItem));
  464.         mbar->GetMenuAndItem(ev, kODCommandPaste, &menuID, &(fEditMenuRec.pasteItem));
  465.         mbar->GetMenuAndItem(ev, kODCommandClear, &menuID, &(fEditMenuRec.clearItem));
  466.  
  467.         mbar->EnableCommand(ev, kODCommandEditMenu,     kODTrue);
  468.         mbar->EnableCommand(ev, kODCommandRedo,         kODFalse);
  469.         mbar->EnableCommand(ev, kODCommandUndo,         kODTrue);
  470.         mbar->EnableCommand(ev, kODCommandCut,             kODTrue);
  471.         mbar->EnableCommand(ev, kODCommandCopy,         kODTrue);
  472.         mbar->EnableCommand(ev, kODCommandPaste,         kODTrue);
  473.         mbar->EnableCommand(ev, kODCommandPasteAs,         kODFalse);
  474.         mbar->EnableCommand(ev, kODCommandClear,         kODTrue);
  475.         mbar->EnableCommand(ev, kODCommandSelectAll,     kODFalse);
  476.         mbar->EnableCommand(ev, kODCommandGetPartInfo,     kODFalse);
  477.         mbar->EnableCommand(ev, kODCommandPreferences,     kODFalse);
  478.         mbar->EnableCommand(ev, kODCommandViewAsWin,     kODFalse);
  479.     
  480.         // Replace contents of Undo menu items with standard strings from rsrc:
  481.         CUsingLibraryResources r;
  482.  
  483.         ODIText* menuText = GetODITextInd(rMenuStrID, kPMUndoStrIndex);
  484.         mbar->SetItemString(ev, kODCommandUndo, menuText);
  485.         DisposeIText(menuText);
  486.  
  487.         menuText = GetODITextInd(rMenuStrID, kPMRedoStrIndex);
  488.         mbar->SetItemString(ev, kODCommandRedo, menuText);
  489.         DisposeIText(menuText);
  490.     }
  491.  
  492.     mbar->Display(ev);
  493. }
  494.     
  495. //---------------------------------------------------------------------------------
  496. // CGXPrinter::RunPageSetupDialog
  497. //---------------------------------------------------------------------------------
  498.  
  499. ODBoolean CGXPrinter::RunPageSetupDialog( Environment *ev )
  500. {
  501.     PrintingEventHandler    idleHandler(ev, fSession, fJob);
  502.     
  503.     this->EnableMenus(ev,kODFalse);
  504.     
  505.     ODBoolean success = (GXJobDefaultFormatDialog(fJob, &fEditMenuRec) == gxOKSelected);
  506.     
  507.     this->EnableMenus(ev,kODTrue);
  508.     
  509.     THROW_IF_JOB_ERROR(fJob);
  510.     
  511.     return success;
  512. }
  513.  
  514. //---------------------------------------------------------------------------------
  515. // CGXPrinter::RunPrintDialog
  516. //---------------------------------------------------------------------------------
  517.  
  518. ODBoolean CGXPrinter::RunPrintDialog(Environment* ev)
  519. {
  520.     ODBoolean success;
  521.  
  522.     TRY
  523.         // Display the Print dialog.
  524.         PrintingEventHandler    idleHandler(ev, fSession, fJob);
  525.  
  526.         this->EnableMenus(ev,kODFalse);
  527.         success = (GXJobPrintDialog(fJob, &fEditMenuRec) == gxOKSelected);
  528.         this->EnableMenus(ev,kODTrue);
  529.     
  530.         THROW_IF_JOB_ERROR(fJob);
  531.     CATCH_ALL
  532.         success = kODFalse;
  533.     ENDTRY
  534.  
  535.     return success;
  536. }
  537.  
  538. //---------------------------------------------------------------------------------
  539. // CGXPrinter::PrintDocument
  540. //---------------------------------------------------------------------------------
  541.  
  542. void CGXPrinter::DoPrint(Environment* ev, ODShape* area)
  543. {
  544.     PrintingEventHandler    idleHandler(ev, fSession, fJob);
  545.  
  546.     this->EnableMenus(ev, kODFalse);
  547.     
  548.     // Check to see if the user wanted to print everything, or just
  549.     // selected pages.
  550.     long firstPage, lastPage;
  551.     GXGetJobPageRange(fJob, &firstPage, &lastPage);
  552.  
  553.     ODULong pageCount = this->CountPages(ev, area);
  554.     if ( lastPage > pageCount ) 
  555.         lastPage = pageCount;
  556.  
  557.     // Print the pages, one at a time.
  558.     for (int page = firstPage; page <= lastPage; page++)
  559.     {
  560.         this->PrintPage(ev, page, area);            // SHAZAM!
  561.     }
  562.  
  563.     this->EnableMenus(ev, kODTrue);
  564. }
  565.  
  566. //---------------------------------------------------------------------------------
  567. // CGXPrinter::PrintAShape  [static method]
  568. //---------------------------------------------------------------------------------
  569.  
  570. OSErr CGXPrinter::PrintAShape(gxShape currentShape, long refCon)
  571. {
  572.     // This is a static method called by the QD->GX translator. Any QuickDraw
  573.     // command in the facet's QD port will be converted to a GX shape and sent here.
  574.     // We just draw it into the printing viewport so the printer will get it.
  575.     
  576.     CGXPrinter*     printer     = (CGXPrinter*)refCon;
  577.     gxShapeType        shapeType     = GXGetShapeType(currentShape);
  578.     ODRect            pageRect    = printer->GetPageRect(somGetGlobalEnvironment());
  579.     
  580.     if ((shapeType == gxEmptyType) || (shapeType == gxFullType) || (shapeType == gxPictureType)
  581.             || GXTouchesBoundsShape((gxRectangle*)&pageRect, currentShape))
  582.     {
  583.         GXSetShapeViewPorts(currentShape, 1, &printer->fViewPort);
  584.         GXDrawShape(currentShape);
  585.     }
  586.     
  587.     return GXGetGraphicsError(kODNULL);
  588. }
  589.  
  590.  
  591. //=================================================================================
  592. // PrintingEventHandler implementation
  593. //=================================================================================
  594.  
  595. Environment*     PrintingEventHandler::sEv = kODNULL;
  596. ODSession*        PrintingEventHandler::sSession = kODNULL;
  597. gxJob            PrintingEventHandler::sgxJob = kODNULL;
  598.  
  599. //---------------------------------------------------------------------------------
  600. // PrintingEventHandler::PrintingEventHandler
  601. //---------------------------------------------------------------------------------
  602.  
  603. PrintingEventHandler::PrintingEventHandler(Environment* ev, ODSession* session, gxJob job)
  604. {
  605.     sEv = ev; 
  606.     sSession = session;
  607.     sgxJob = job;
  608.     
  609.     fgxJob = job;
  610.     fPrintingEventOverrideProcPtr = NewGXPrintingEventProc(PrintingEventHandler::PrintingEventOverride);
  611.  
  612.     GXInstallApplicationOverride(fgxJob, gxPrintingEventMsg, fPrintingEventOverrideProcPtr);
  613. }
  614.  
  615. //---------------------------------------------------------------------------------
  616. // PrintingEventHandler::~PrintingEventHandler
  617. //---------------------------------------------------------------------------------
  618.  
  619. PrintingEventHandler::~PrintingEventHandler()
  620. {
  621.     GXInstallApplicationOverride(fgxJob, gxPrintingEventMsg, kODNULL);
  622.  
  623.     DisposeRoutineDescriptor(fPrintingEventOverrideProcPtr);
  624.  
  625.     sEv = kODNULL;
  626.     sSession = kODNULL;
  627. }
  628.  
  629. //---------------------------------------------------------------------------------
  630. // PrintingEventHandler::PrintingEventOverride
  631. //---------------------------------------------------------------------------------
  632.  
  633. OSErr PrintingEventHandler::PrintingEventOverride(EventRecord* anEvent, Boolean filterEvent)
  634. {
  635.     // this is a static method used as a callback by GX...
  636.     
  637.     WASSERT(sSession != kODNULL);
  638.     WASSERT(sEv != kODNULL);
  639.  
  640.     //WARN("Within SBPrintingEventHandler::SBPrintingEventOverride");
  641.  
  642.     if (!filterEvent)
  643.     {
  644.         switch(anEvent->what)
  645.         {
  646.             case nullEvent:
  647.             case mouseDown:
  648.             case keyDown:
  649.             case autoKey:
  650.                 break;
  651.             
  652.             case osEvt:
  653.                 // Update the job on a resume event in case user changed printer in Finder:
  654.                 if( ((anEvent->message>>24) & 0x00FF)==0x01 && (anEvent->message & 0x01) ) {
  655.                     GXUpdateJob(sgxJob);
  656.                 }
  657.                 // continue to default case:
  658.                 
  659.             default:
  660.                 TRY{
  661.                     ODDispatcher* dispatcher = sSession->GetDispatcher(sEv);
  662.                     if (dispatcher)
  663.                         dispatcher->Dispatch(sEv, (ODEventData*)anEvent);
  664.                 }CATCH_ALL{
  665.                     WARN("Error dispatching event");
  666.                 }ENDTRY
  667.                 break;
  668.         }
  669.     }
  670.     
  671.     return noErr;
  672. }
  673.